package com.study.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * ApplicationContextAwareProcessor 帮我们实现的
 * 实现 ApplicationContextAware 接口，重写 setApplicationContext 方法，将传进来的 ioc 容器保存起来 就可以得到 ioc 容器
 * @author wuwenbo
 * @date 2020/4/3 - 18:57
 */
@Component
public class Dog implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    public Dog() {System.out.println("dog...constructor...");
    }
    //对象创建并赋值之后调用
    @PostConstruct
    public void init(){
        System.out.println("dog...@PostConstruct...");
    }
    //容器移除之前
    @PreDestroy
    public void destory(){
        System.out.println("dog...@PreDestroy");
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    this.applicationContext = applicationContext;
    }
    public ApplicationContext getApplicationContext() {
       return applicationContext;
    }
}

